﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using FineUI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data;

namespace IHISCETeim.Web.AgentSys.SvrMgr
{
    public partial class AgentQltyVisitVisit : AgentPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }
        protected override string DWZRef
        {
            get { return "AgentQltyVisitList"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetConfirmHideReference();
            CheckPowerWithButton(Permission.修改, btnSaveClose);


            showInfo.NavigateUrl = string.Format("javascript:onShowMac({0},'{1}')",viewObj.QltyId,qltyObj.ClaimsNumber);

            this.CustomerName.Text = qltyObj.CustomerName + qltyObj.CustomerMobile;
            this.FaultDate.Text = qltyObj.FaultDate.ToString("yyyy-MM-dd");
            this.FaultDescription.Text = StringHelper.StripTags(qltyObj.FaultDescription, false);
            //
            IsTimeOut.Label = string.Format(IsTimeOut.Label, viewObj.AgentName);
            //初始化数据,如果是已访回过.就可以直接查看
            this.IsRemoval.Checked = viewObj.IsRemoval;
            this.IsTimeOut.Checked = viewObj.IsTimeOut;
            this.TimeHowLong.Text = viewObj.TimeHowLong.ToString();
            this.IsOneGood.Checked = viewObj.IsOneGood;
            this.OneHowLong.Text = viewObj.OneHowLong.ToString();
            this.IsOperation.Checked = viewObj.IsOperation;
            this.IsMatter.Checked = viewObj.IsMatter;
            this.RepairTechnology.Text = viewObj.RepairTechnology.ToString();
            this.ServiceAttitude.Text = viewObj.ServiceAttitude.ToString();
            this.OtherRemark.Text = viewObj.OtherRemark.ToString();
            this.IsSrvAct.Checked = viewObj.IsSrvAct;
        }

        private int ID
        {
            get {
                return GetRequestValue<int>("id", 0);
            }
        }
        protected AgentQltyVisitInfo _viewObj = null;
        protected AgentQltyVisitInfo viewObj
        {
            get {
                if (_viewObj == null)
                    _viewObj = AgentQltyVisitController.GetByID(ID);
                return _viewObj;
            }
        }
        protected AgentQltyInfo _qltyObj = null;
        protected AgentQltyInfo qltyObj
        {
            get
            {
                if (_qltyObj == null)
                    _qltyObj = AgentQltyController.GetByQltyId(viewObj.QltyId);
                return _qltyObj;
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            try
            {
                viewObj.RealDate = DateTime.Now;
                viewObj.IsRemoval = this.IsRemoval.Checked;
                viewObj.IsVisit = true;
                viewObj.IsTimeOut = IsTimeOut.Checked;
                viewObj.TimeHowLong = Convert.ToDecimal(TimeHowLong.Text);
                viewObj.IsOneGood = IsOneGood.Checked;
                viewObj.OneHowLong = Convert.ToDecimal(OneHowLong.Text);
                viewObj.IsOperation = IsOperation.Checked;
                viewObj.IsMatter = IsMatter.Checked;
                viewObj.RepairTechnology = Convert.ToInt32(RepairTechnology.Text);
                viewObj.ServiceAttitude = Convert.ToInt32(ServiceAttitude.Text);
                viewObj.OtherRemark = OtherRemark.Text;
                viewObj.IsSrvAct = IsSrvAct.Checked;
                viewObj.SrvActUserId = viewObj.IsSrvAct ? qltyObj.SrvActUserId : 0;

                if (AgentQltyVisitController.Update(viewObj))
                {
                    Alert.Show("已成功提交回访");
                    //ActiveWindow.
                    // Alert.getsho;
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());//.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.Show("回访失败！", "提示", MessageBoxIcon.Error);
                }
            }
            catch {
                Alert.Show("数据填写错误！", "提示", MessageBoxIcon.Error);
            }
        }
        
    }
}